package firstchi.graceplayer;

import android.app.Dialog;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Notification;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.database.Cursor;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.os.Handler;
import android.os.Message;
import android.provider.MediaStore;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.CompoundButton;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.SeekBar;
import android.widget.SimpleAdapter;
import android.widget.Switch;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;

public class MainActivity extends AppCompatActivity {

    private ImageButton imgBtn_Previous;
    private ImageButton imgBtn_PlayOrPause;
    private ImageButton imgBtn_Stop;
    private ImageButton imgBtn_Next;
    private ListView list;

    private ArrayList<Music>musicArrayList;
    private MediaPlayer player =new MediaPlayer();

    private int number =0 ;
    private int status;
    private StatusChangedReceiver receiver;
    private RelativeLayout root_Layout;
    private TextView textView;
    private Handler seekBarHandler;
    private TextView text_Current;
    private TextView text_Duration;
    private int duration;
    private int time;
    private SeekBar seekBar;
    private Handler SeekBarHandler;
    private static final int PGOGRESS_INCRESE=0;
    private static final int PGOGRESS_PAUSE=1;
    private static final int PGOGRESS_RESET=2;

    private static final int MODE_LIST_SEQUENCE=0;
    private static final int MODE_SINGLE_CYCLE=1;
    private static final int MODE_LIST_CYCLE=2;
    private int playmode;
    private static boolean isExit=false;

    private TextView tv_vol;
    private SeekBar seekbar_vol;

    private ImageView iv_sleep;
    private Timer timer_sleep;
    private static final boolean NOTSLEEP=false;
    private static final boolean ISSLEEP=true;
    private int sleepminute=20;
    private static boolean sleepmode;







    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        findViews();
        registerListeners();
        initMusicList();
        initListView();
        checkMusicfile();
        bindStatusChangeReceiver();
        initSeekBarHandler();
        duration=0;
        time=0;
        startService(new Intent(this,MusicService.class));
        status=MusicService.COMMAND_STOP;

        playmode = MainActivity.MODE_LIST_SEQUENCE;
        sleepmode=MainActivity.NOTSLEEP;

    }

    private void bindStatusChangeReceiver(){
        receiver=new StatusChangedReceiver();
        IntentFilter filter =new IntentFilter(
                MusicService.BROADCAST_MUSICSERVICE_UPDATE_STATUS
        );
        registerReceiver(receiver,filter);
    }
    @Override
    public boolean onKeyDown(int keyCode,KeyEvent event){
        int progress;
        switch (keyCode){
            case KeyEvent.KEYCODE_BACK:
                exitByDoubleClick();
                break;
            case KeyEvent.KEYCODE_VOLUME_DOWN:
                progress=seekbar_vol.getProgress();
                if (progress!=0)
                    seekbar_vol.setProgress(progress-1);
                return true;
            case KeyEvent.KEYCODE_VOLUME_UP:
                progress=seekbar_vol.getProgress();
                if (progress!=seekbar_vol.getMax())
                    seekbar_vol.setProgress(progress+1);
                return true;
            default:
                break;
        }
        return false;
    }

    private void exitByDoubleClick()
    {
        Timer timer=null;
        if(isExit==false)
        {
            isExit=true;
            Toast.makeText(this,"再按一次退出程序!",Toast.LENGTH_SHORT).show();
            timer =new Timer();
            timer.schedule(new TimerTask() {
                @Override
                public void run() {
                    isExit=false;
                }
            },2000);
        }
        else{
            System.exit(0);
        }
    }



    private void findViews(){
        imgBtn_Previous = (ImageButton) findViewById(R.id.imageButton1);
        imgBtn_PlayOrPause =(ImageButton) findViewById(R.id.imageButton2);
        imgBtn_Stop =(ImageButton) findViewById(R.id.imageButton3);
        imgBtn_Next =(ImageButton) findViewById(R.id.imageButton4);
        list =(ListView) findViewById(R.id.listView1);

        seekBar=(SeekBar)findViewById(R.id.seekBar1);
        text_Current=(TextView)findViewById(R.id.textView1);
        text_Duration=(TextView)findViewById(R.id.textView2);
        textView=(TextView)findViewById(R.id.textView);

        tv_vol=(TextView)findViewById(R.id.main_tv_volumeText);
        seekbar_vol=(SeekBar) findViewById(R.id.main_sb_volumebar);
        iv_sleep=(ImageView)findViewById(R.id.main_iv_sleep);



        root_Layout = (RelativeLayout) findViewById(R.id.relativeLayout2);



    }

    private void registerListeners(){
        imgBtn_Previous.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                sendBroadcastOnCommand(MusicService.COMMAND_PREVIOUS);


            }
        });

        imgBtn_PlayOrPause.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                switch (status){
                    case MusicService.STATUS_PLAYING:
                        sendBroadcastOnCommand(MusicService.COMMAND_PAUSE);
                        break;
                    case MusicService.STATUS_PAUSED:
                        sendBroadcastOnCommand(MusicService.COMMAND_RESUME);
                        break;
                    case MusicService.COMMAND_STOP:
                        sendBroadcastOnCommand(MusicService.COMMAND_PLAY);
                        default:
                            break;
                }

            }
        });

        imgBtn_Stop.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                sendBroadcastOnCommand(MusicService.COMMAND_STOP);

            }
        });

        imgBtn_Next.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                sendBroadcastOnCommand(MusicService.COMMAND_NEXT);
            }
        });
        list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                number=i;
                sendBroadcastOnCommand(MusicService.COMMAND_PLAY);}
        });
        seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener(){
            @Override
            public void onStopTrackingTouch(SeekBar seekBar){
                if(status!=MusicService.STATUS_STOPPED){
                    time = seekBar.getProgress();
                    text_Current.setText(formatTime(time));
                    sendBroadcastOnCommand(MusicService.COMMAND_SEEK_TO);
                }
                if(status==MusicService.STATUS_PLAYING){
                    sendBroadcastOnCommand(MusicService.COMMAND_SEEK_TO);
                    seekBarHandler.sendEmptyMessageDelayed(PGOGRESS_INCRESE,1000);
                }
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
                //进度条暂停移动
                seekBarHandler.sendEmptyMessage(PGOGRESS_PAUSE);
            }
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            }
        });


    }

    private void initMusicList(){
        musicArrayList =MusicList.getMusicList();
        if(musicArrayList.isEmpty())
        {
            Cursor mMusicCursor = this.getContentResolver().query(
                    MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
                    new String[] {
                            MediaStore.Audio.Media.TITLE,
                            MediaStore.Audio.Media.DURATION,
                            MediaStore.Audio.Media.ALBUM,
                            MediaStore.Audio.Media.ARTIST,
                            MediaStore.Audio.Media._ID,
                            MediaStore.Audio.Media.DATA,
                            MediaStore.Audio.Media.DISPLAY_NAME
                    },null,null, MediaStore.Audio.Media.TITLE
            );


            if (mMusicCursor !=null) {
                int indexTitle = mMusicCursor.getColumnIndex(MediaStore.Audio.AudioColumns.TITLE);
                int indexArtist = mMusicCursor.getColumnIndex(MediaStore.Audio.AudioColumns.ARTIST);
                int indexTotalTime = mMusicCursor.getColumnIndex(MediaStore.Audio.AudioColumns.DURATION);
                int indexPath = mMusicCursor.getColumnIndex(MediaStore.Audio.AudioColumns.DATA);



                for (mMusicCursor.moveToFirst(); !mMusicCursor.isAfterLast(); mMusicCursor.moveToNext()) {
                    String strTitle = mMusicCursor.getString(indexTitle);
                    String strArtist = mMusicCursor.getString(indexArtist);
                    String strTotoalTime = mMusicCursor.getString(indexTotalTime);
                    String strPath = mMusicCursor.getString(indexPath);



                    if (strArtist.equals("<unknown>")){
                        strArtist = "无艺术家";
                    Music music = new Music(strTitle, strArtist, strPath, strTotoalTime);
                    musicArrayList.add(music);
                }else{
                Music music=new Music(strTitle,strArtist,strPath,strTotoalTime);
                musicArrayList.add(music);}
                }
            }





        }
    }
    private void initListView(){
        List<Map<String, String>> list_map = new ArrayList<Map<String,String>>();
        HashMap<String,String>map;
        SimpleAdapter simpleAdapter;
        for (Music music:musicArrayList){
            map = new HashMap<String, String>();
            map.put("musicName",music.getmusicName());
            map.put("musicArtist",music.getmusicArtist());
            list_map.add(map);
        }

        String[] from = new String[]{"musicName","musicArtist"};
        int[] to ={R.id.listview_tv_title_item,R.id.listview_tv_artist_item};

        simpleAdapter = new SimpleAdapter(this,list_map,R.layout.listview,from,to);
        list.setAdapter(simpleAdapter);

    }
    private  void checkMusicfile()
    {
        if (musicArrayList.isEmpty()){
            imgBtn_Next.setEnabled(false);
            imgBtn_PlayOrPause.setEnabled(false);
            imgBtn_Previous.setEnabled(false);
            imgBtn_Stop.setEnabled(false);
            Toast.makeText(getApplicationContext(),"当前没有歌曲文件",Toast.LENGTH_SHORT).show();
        }else {
            imgBtn_Next.setEnabled(true);
            imgBtn_PlayOrPause.setEnabled(true);
            imgBtn_Previous.setEnabled(true);
            imgBtn_Stop.setEnabled(true);
        }
    }


    private void audio_Control(){
        final AudioManager audioManager=(AudioManager)this.getSystemService(Context.AUDIO_SERVICE);
        this.setVolumeControlStream(AudioManager.STREAM_MUSIC);
        final int max_progress=audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
        seekbar_vol.setMax(max_progress);
        int progress=audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
        seekbar_vol.setProgress(progress);
        tv_vol.setText("音量："+(progress*100/max_progress)+"%");
        seekbar_vol.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener(){
            @Override
            public void onStopTrackingTouch(SeekBar arg0){

            }
            @Override
            public void onStartTrackingTouch(SeekBar ar0){

            }

            @Override
            public void onProgressChanged(SeekBar arg0,int arg1,boolean arg2){
                tv_vol.setText("音量"+(arg1*100)/(max_progress)+"%");
                audioManager.setStreamVolume(AudioManager.STREAM_MUSIC,arg1,AudioManager.FLAG_PLAY_SOUND);
            }
        });
    }


    protected void onResume(){
        super.onResume();
        sendBroadcastOnCommand(MusicService.COMMAND_CHECK_IS_PLAYING);
    PropertyBean property=new PropertyBean(MainActivity.this);
        String theme = property.getTheme();
        setTheme(theme);
        audio_Control();
        if(sleepmode==MainActivity.ISSLEEP)iv_sleep.setVisibility(View.VISIBLE);
        else iv_sleep.setVisibility(View.INVISIBLE);
    }

    private  void sendBroadcastOnCommand(int command){
        Intent intent = new Intent(MusicService.BROADCAST_MUSICSERVICE_CONTROL);
        intent.putExtra("command",command);
        switch(command){
            case MusicService.COMMAND_PLAY:
                intent.putExtra("number",number);
                break;
            case MusicService.COMMAND_SEEK_TO:
                intent.putExtra("time",time);
                break;
            case MusicService.COMMAND_PREVIOUS:
            case MusicService.COMMAND_NEXT:
            case MusicService.COMMAND_PAUSE:
            case MusicService.COMMAND_STOP:
            case MusicService.COMMAND_RESUME:

            default:
                break;

        }
        sendBroadcast(intent);
    }
    private String formatTime (int msec){
        int minute=msec/1000/60;
        int second =msec /1000%60;
        String minuteString;
        String secondString;
        if(minute<10){
            minuteString="0"+minute;
        }else{
            minuteString="0"+second;
        }

        if(second<10){
            secondString="0"+second;

        }else{
            secondString=""+second;

        }
        return minuteString+":"+secondString;
    }

    public String musicName;
    public String musicArtist;

    class StatusChangedReceiver extends BroadcastReceiver{
        public void onReceive(Context context,Intent intent){
            status = intent.getIntExtra("status",-1);

            String musicName = intent.getStringExtra("musicName");
            String musicArtist = intent.getStringExtra("musicArtist");

            switch(status){
                case MusicService.STATUS_PLAYING:



                            seekBarHandler.removeMessages(PGOGRESS_INCRESE);
                            time=intent.getIntExtra("time",0);

                            duration=intent.getIntExtra("duration",0);
                            number=intent.getIntExtra("number",number);
                            list.setSelection(number);
                            seekBar.setProgress(time);
                            seekBar.setMax(duration);
                            seekBarHandler.sendEmptyMessageDelayed(PGOGRESS_INCRESE,1000);
                            text_Duration.setText(formatTime(duration));
                            imgBtn_PlayOrPause.setBackgroundResource(R.drawable.pause);
                    textView.setText("正在播放"+musicName+"-"+musicArtist);
                            MainActivity.this.setTitle("正在播放");
                            break;


                case MusicService.STATUS_PAUSED:
                    seekBarHandler.sendEmptyMessage(PGOGRESS_PAUSE);
                    imgBtn_PlayOrPause.setBackgroundResource(R.drawable.play);
                    MainActivity.this.setTitle("正在播放");
                    textView.setText("正在播放"+musicName+"-"+musicArtist);
                    String string=MainActivity.this.getTitle().toString().replace("正在播放","已暂停");
                    MainActivity.this.setTitle(string);
                    break;
                case MusicService.STATUS_STOPPED:
                    time =0;
                    duration=0;
                    text_Current.setText(formatTime(time));
                    text_Duration.setText(formatTime(duration));
                    seekBarHandler.sendEmptyMessage(PGOGRESS_RESET);
                    textView.setText("正在播放"+musicName+"-"+musicArtist);
                    MainActivity.this.setTitle("GracePlayer");
                    imgBtn_PlayOrPause.setBackgroundResource(R.drawable.play);
                    break;
                case MusicService.STATUS_COMPLETED:
                    number=intent.getIntExtra("number",0);
                    if(playmode==MainActivity.MODE_LIST_SEQUENCE) {
                        if (number == MusicList.getMusicList().size() - 1)

                            sendBroadcastOnCommand(MusicService.STATUS_STOPPED);
                        else
                            sendBroadcastOnCommand(MusicService.COMMAND_NEXT);
                    }

                    else if(playmode==MainActivity.MODE_SINGLE_CYCLE)
                        sendBroadcastOnCommand(MusicService.COMMAND_PLAY);
                    else if(playmode==MainActivity.MODE_LIST_CYCLE)
                    {
                        if(number==MusicList.getMusicList().size()-1){
                            number=0;
                            sendBroadcastOnCommand(MusicService.COMMAND_PLAY);
                        }else sendBroadcastOnCommand(MusicService.COMMAND_NEXT);
                    }
                seekBarHandler.sendEmptyMessage(PGOGRESS_RESET);

                    MainActivity.this.setTitle("GracePlayer");
                    imgBtn_PlayOrPause.setBackgroundResource(R.drawable.play);

                    break;
                default:
                    break;
            }
        }
    }
    protected void onDestroy() {
        // TODO Auto-generated method stub
        if (status == MusicService.STATUS_STOPPED) {
            stopService(new Intent(this, MusicService.class));
        }
        super.onDestroy();
    }

    private void setTheme(String theme) {
        if ("彩色".equals(theme)) {
            this.root_Layout.setBackgroundResource(R.drawable.bg_color);
        } else if ("花朵".equals(theme)) {
            this.root_Layout.setBackgroundResource(R.drawable.bg_digit_flower);
        } else if ("群山".equals(theme)) {
            this.root_Layout.setBackgroundResource(R.drawable.bg_mountain);
        } else if ("小狗".equals(theme)) {
            this.root_Layout.setBackgroundResource(R.drawable.bg_running_dog);
        } else if ("冰雪".equals(theme)) {
            this.root_Layout.setBackgroundResource(R.drawable.bg_snow);
        } else if ("女孩".equals(theme)) {
            this.root_Layout.setBackgroundResource(R.drawable.bg_music_girl);
        } else if ("朦胧".equals(theme)) {
            this.root_Layout.setBackgroundResource(R.drawable.bg_blur);
        }
    }


    public boolean onCreateOptionsMenu(Menu menu){
        this.getMenuInflater().inflate(R.menu.menu,menu);
        return super.onCreateOptionsMenu(menu);
    }
    public boolean onOptionsItemSelected(MenuItem item){
        switch (item.getItemId()) {
            case R.id.menu_theme:
                new AlertDialog.Builder(this)
                        .setTitle("请选择主题")
                        .setItems(R.array.theme,
                                new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dialog, int which) {
                                        String theme = PropertyBean.THEMES[which];
                                        setTheme(theme);
                                        PropertyBean property = new PropertyBean(MainActivity.this);
                                        property.setAndSaveTheme(theme);
                                    }
                                }).show();
                break;

            case R.id.menu_about:
                new AlertDialog.Builder(MainActivity.this).setTitle("GracePlayer")
                        .setMessage(R.string.about2).show();
                break;
            case R.id.menu_playmode:
                String[] mode = new String[]{"順序播放", "單曲循環", "列表循環"};
                AlertDialog.Builder builder = new AlertDialog.Builder(
                        MainActivity.this
                );
                builder.setTitle("播放模式");
                builder.setSingleChoiceItems(mode, playmode,
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface arg0, int arg1) {
                                playmode = arg1;
                            }
                        });

                builder.setPositiveButton("確定",
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface arg0, int arg1) {
                                switch (playmode) {
                                    case 0:
                                        playmode = MainActivity.MODE_LIST_SEQUENCE;
                                        Toast.makeText(getApplicationContext(), R.string.sequence, Toast.LENGTH_SHORT).show();
                                        break;
                                    case 1:
                                        playmode = MainActivity.MODE_SINGLE_CYCLE;
                                        Toast.makeText(getApplicationContext(), R.string.singlecycle, Toast.LENGTH_SHORT).show();
                                        break;
                                    case 2:
                                        playmode = MainActivity.MODE_LIST_CYCLE;
                                        Toast.makeText(getApplicationContext(), R.string.listcycle, Toast.LENGTH_SHORT).show();
                                        break;
                                    default:
                                        break;
                                }
                            }

                        });
                builder.create().show();
                break;

            case R.id.menu_sleep:
                showSleepDialog();
                break;



            case R.id.menu_quit:
                new AlertDialog.Builder(MainActivity.this).setTitle("提示")
                        .setMessage(R.string.quit_message).setPositiveButton("确定",new DialogInterface.OnClickListener(){
                    public void onClick(DialogInterface arg0,int arg1){System.exit(0);}


                }).setNegativeButton("取消",new DialogInterface.OnClickListener(){
            public void onClick(DialogInterface arg0,int arg1){}
        }).show();
        break;
        }
        return super.onOptionsItemSelected(item);
    }
    private void initSeekBarHandler() {
        seekBarHandler = new Handler() {
            public void handleMessage(Message msg) {
                super.handleMessage(msg);
                switch (msg.what) {
                    case PGOGRESS_INCRESE:
                        if (seekBar.getProgress() < duration) {
                            //进度条前进一秒
                            seekBar.setProgress(time);
                            seekBar.incrementProgressBy(1000);
                            seekBarHandler.sendEmptyMessageDelayed(PGOGRESS_INCRESE, 1000);
                            //修改显示当前进度的文本
                            text_Current.setText(formatTime(time));
                            time += 1000;
                        }
                        break;
                    case PGOGRESS_PAUSE:
                        seekBarHandler.removeMessages(PGOGRESS_INCRESE);
                        break;
                    case PGOGRESS_RESET:
                        //重置进度条画面
                        seekBarHandler.removeMessages(PGOGRESS_INCRESE);
                        seekBar.setProgress(0);
                        text_Current.setText("00:00");
                        break;
                }
            }
        };
    }
    private void showSleepDialog(){
        final View userview =this.getLayoutInflater().inflate(R.layout.dialog,null);
        final TextView tv_minute=(TextView)userview.findViewById(R.id.dialog_tv);
        final Switch switch1=(Switch)userview.findViewById(R.id.dialog_switch);
        final SeekBar seekbar=(SeekBar)userview.findViewById(R.id.dialog_seekbar);
        tv_minute.setText("睡眠于:"+sleepminute+"分鐘");
        if(sleepmode==MainActivity.ISSLEEP)switch1.setChecked(true);
        seekbar.setMax(60);
        seekbar.setProgress(sleepminute);
        seekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener(){
            @Override
            public void onStopTrackingTouch(SeekBar arg0){

            }
            @Override
            public void onStartTrackingTouch(SeekBar arg0){

            }
            @Override
            public void onProgressChanged(SeekBar arg0,int arg1,boolean arg2){
                sleepminute=arg1;
                tv_minute.setText("睡眠于"+sleepminute+"分鐘");
            }



        });
        switch1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
                sleepmode =arg1;
            }
        });
        final TimerTask timerTask =new TimerTask() {
            @Override
            public void run() {
                System.exit(0);
            }
        };
        final AlertDialog.Builder dialog=new AlertDialog.Builder(this);
        dialog.setTitle("選擇睡眠時間（0~60分鐘");
        dialog.setView(userview);
        dialog.setNegativeButton("取消",new DialogInterface.OnClickListener(){
            public void onClick(DialogInterface arg0,int arg1){
                arg0.dismiss();
            }
        });
        dialog.setNeutralButton("重置",new DialogInterface.OnClickListener(){
            public void onClick(DialogInterface arg0,int arg1){
                if (sleepmode==MainActivity.ISSLEEP){
                    timerTask.cancel();
                    timer_sleep.cancel();
                }
                sleepmode=MainActivity.NOTSLEEP;
                sleepminute=20;
                iv_sleep.setVisibility(View.INVISIBLE);
            }
        });
        dialog.setPositiveButton("確定",new DialogInterface.OnClickListener(){
            public void onClick(DialogInterface arg0,int arg1){
                if (sleepmode == MainActivity.ISSLEEP) {
                timer_sleep=new Timer();
                    int time =seekbar.getProgress();
                    timer_sleep.schedule(timerTask, time*60*1000);
                    iv_sleep.setVisibility(View.VISIBLE);

                }
                else {
                    timerTask.cancel();
                    if (timer_sleep!=null)timer_sleep.cancel();
                    arg0.dismiss();
                    iv_sleep.setVisibility(View.VISIBLE);
                }
                }

        });
        dialog.show();

    }



    /*private void load(int number) {
        try {
            player.reset();
            player.setDataSource(MusicList.getMusicList().get(number).getmusicPath());
            player.prepare();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    private void play(int number) {
        // ֹͣ停止当前播放
        if (player != null && player.isPlaying()) {
            player.stop();
        }
        load(number);
        player.start();
    }

    private void pause() {
        if (player.isPlaying()) {
            player.pause();
        }
    }

    private void stop() {
        player.stop();
    }

    private void resume() {
        player.start();
    }

    private void replay() {
        player.start();
    }


    private void moveNumberToNext() {
        // 判断是否到达列表底端
        if ((number ) == MusicList.getMusicList().size()-1) {
            Toast.makeText(MainActivity.this,MainActivity.this.getString(R.string.tip_reach_bottom),Toast.LENGTH_SHORT).show();
        } else {
            ++number;
            play(number);
        }
    }


    private void moveNumberToPrevious() {
        // 判断是否到达列表顶端
        if (number == 0) {
            Toast.makeText(MainActivity.this,MainActivity.this.getString(R.string.tip_reach_top),Toast.LENGTH_SHORT).show();
        } else {
            --number;
            play(number);
        }
    }*/






}
